package com.culture.config.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import javax.validation.Valid;

import com.culture.config.common.model.ResponseData;
import com.culture.config.common.util.ResponseUtil;
import com.culture.config.service.RoleService;
import com.culture.config.model.po.RoleAddPO;
import com.culture.config.model.po.RoleSearchPO;
import com.culture.config.model.po.RolePageParam;
import com.culture.config.model.po.RoleUpdatePO;
import com.culture.config.model.vo.RoleVO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api
@RestController
@RequestMapping("/api/role")
public class RoleController extends BaseController {
	 @Autowired
	 private RoleService roleService;
	 
	@ApiOperation("page role")
	@PreAuthorize(value = "hasRole('ROLE_admin')")
	@PostMapping("/page")
    public ResponseData<List<RoleVO>> page(@RequestBody @Valid RolePageParam param){
        this.authenticationValidate();
        return ResponseUtil.successPage(this.roleService.page(param));
    }

    @ApiOperation("list role")
	@PreAuthorize(value = "hasRole('ROLE_admin')")
	@PostMapping("/list")
    public ResponseData<List<RoleVO>> list(@RequestBody @Valid RoleSearchPO param){
        this.authenticationValidate();
        return ResponseUtil.success(this.roleService.list(param));
    }

    @ApiOperation("add menu")
	@PreAuthorize(value = "hasRole('ROLE_root')")
	@PostMapping("/add")
    public ResponseData<String> add(@RequestBody @Valid RoleAddPO roleAddPO){
        this.authenticationValidate();
        this.roleService.add(roleAddPO);
        return ResponseUtil.success();
    }

    @ApiOperation("update menu")
	@PreAuthorize(value = "hasRole('ROLE_root')")
	@PostMapping("/update")
    public ResponseData<String> update(@RequestBody @Valid RoleUpdatePO roleUpdatePO){
        this.authenticationValidate();
        this.roleService.update(roleUpdatePO);
        return ResponseUtil.success();
    }
}
